package com.ruoyi.app.controller.business.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.customer.domain.JbOpportunity;
import com.ruoyi.business.customer.domain.vo.JbOpportunityListVo;
import com.ruoyi.business.customer.service.JbOpportunityService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 商机 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("商机")
@RestController
@RequestMapping("/app/opportunity")
public class AppJbOpportunityController extends BaseController
{
    @Autowired
    private JbOpportunityService service;

    /**
     * 获取商机详细信息
     */
    @ApiOperation("获取商机详细信息")
    @GetMapping(value = "/getDetails/{id}")
    public AjaxResult getDetails(@PathVariable("id") Long id)
    {
        return success(service.getInfo(id));
    }


    /**
     * 我的商机列表
     */
    @ApiOperation("我的商机列表")
    @GetMapping("/myDataList")
    public TableDataInfo myDataList(PageParam page, JbOpportunity jbOpportunity)
    {
        jbOpportunity.setOpportunityDataType(Constants.PUBLIC_NUMBER_3);
        jbOpportunity.setBusinessManagerId(getUserId());
        IPage<JbOpportunityListVo> iPage = service.pageList(page, jbOpportunity);
        return getDataTable(iPage.getRecords());

    }

    /**
     * 获取商机数据
     */
    @ApiOperation("获取商机详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增商机
     */
    @ApiOperation("新增商机")
    @Log(title = "新增商机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbOpportunity jbOpportunity)
    {
        return toAjax(service.save(jbOpportunity));
    }

    /**
     * 修改商机
     */
    @ApiOperation("修改商机")
    @Log(title = "修改商机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbOpportunity jbOpportunity)
    {
        return toAjax(service.updateById(jbOpportunity));
    }

    /**
     * 删除商机
     */
    @ApiOperation("删除商机")
    @Log(title = "删除商机", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.removeByIds(Arrays.asList(ids)));
    }


}
